package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: bjc
 * Date: 2025-08-13
 * Time: 17:28
 */
class MyThread2 extends Thread {
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("hello thread");
        }
    }
}
public class ThreadDemo2 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new MyThread2();
        t.start();//在系统内核中创建出线程，然后执行MyThread2中的重写的方法。
        while (true){
            Thread.sleep(1000);//休眠1秒，单位是毫秒
            System.out.println("hello main");
        }
    }
}
